package model

import (
	"manager/model/entity"

	"manager/model/po"

	"github.com/lib/pq"
)

// RepairCreateRequest 创建现场数据
type RepairCreateRequest struct {
	Reportman int64 `json:"reportman"`

	EbikeId int64 `json:"ebike_id"`

	FaultId   int64  `json:"fault_id"`
	FaultName string `json:"fault_name"`

	FaultTypeId   int64  `json:"fault_type_id"`
	FaultTypeName string `json:"fault_type_name"`

	EbikeTypeId    int64  `json:"ebike_type_id"`
	EbikeTypeName  string `json:"ebike_type_name"`
	EbikeTypeImage string `json:"ebike_type_image"`

	Other string `json:"other"`

	Type int `json:"type"`

	Coordinate po.Point `json:"coordinate"`

	Photo pq.StringArray `json:"photo"`

	OrderNo string `json:"order_no"`

	Status int `json:"status"`

	Repairman int64 `json:"repairman"`

	Price int64 `json:"price"`

	StoreId int64 `json:"store_id"`

	Desc string `json:"desc"`

	RepairAt int64 `json:"repair_at"`

	UpdatedAt int64 `json:"updated_at"`
}

// RepairUpdateRequest 更新现场数据
type RepairUpdateRequest struct {
	Id int64 `json:"id"`

	Reportman *int64 `json:"reportman"`

	EbikeId *int64 `json:"ebike_id"`

	FaultId *int64 `json:"fault_id"`

	Other *string `json:"other"`

	Type *int `json:"type"`

	Coordinate *po.Point `json:"coordinate"`

	Photo *pq.StringArray `json:"photo"`

	OrderNo *string `json:"order_no"`

	Status *int `json:"status"`

	Repairman *int64 `json:"repairman"`

	Price *int64 `json:"price"`

	StoreId *int64 `json:"store_id"`

	Desc *string `json:"desc"`

	FaultName *string `json:"fault_name"`

	FaultTypeId   *int64  `json:"fault_type_id"`
	FaultTypeName *string `json:"fault_type_name"`

	EbikeTypeId    *int64  `json:"ebike_type_id"`
	EbikeTypeName  *string `json:"ebike_type_name"`
	EbikeTypeImage *string `json:"ebike_type_image"`

	RepairAt *int64 `json:"repair_at"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt *int64 `json:"updated_at"`
}

// RepairListRequest 列表现场数据
type RepairListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	Id int64 `json:"id"`

	OrderNos []string `json:"order_nos"`

	Reportman *int64 `json:"reportman"`

	EbikeId *int64 `json:"ebike_id"`

	FaultId *int64 `json:"fault_id"`

	FaultName     *string `json:"fault_name"`
	FaultTypeId   *int64  `json:"fault_type_id"`
	FaultTypeName *string `json:"fault_type_name"`

	EbikeTypeId    *int64  `json:"ebike_type_id"`
	EbikeTypeName  *string `json:"ebike_type_name"`
	EbikeTypeImage *string `json:"ebike_type_image"`

	Other *string `json:"other"`

	Type *int `json:"type"`

	Coordinate *po.Point `json:"coordinate"`

	Photo *pq.StringArray `json:"photo"`

	OrderNo *string `json:"order_no"`

	Status *int `json:"status"`

	Repairman *int64 `json:"repairman"`

	Price *int64 `json:"price"`

	StoreId *int64 `json:"store_id"`

	Desc *string `json:"desc"`

	RepairAt *int64 `json:"repair_at"`

	UpdatedAt *int64 `json:"updated_at"`

	AcceptedAt *int64 `json:"accepted_at"`

	StartTime *int64 `json:"start_time"`
	EndTime   *int64 `json:"end_time"`

	TimeZone []int64 `json:"time_zone"`
}

// RepairListResponse 列表回包数据
type RepairListResponse struct {
	Total int           `json:"total"`
	List  []*RepairInfo `json:"list"`
}

// RepairInfoRequest 列表现场数据
type RepairInfoRequest struct {
	Id int64 `json:"id"`
}

// RepairInfoResponse 列表回包数据
type RepairInfoResponse struct {
	Info *RepairInfo `json:"info"`
}

// RepairInfo 详细数据
type RepairInfo struct {
	Id int64 `json:"id"`

	Reportman int64 `json:"reportman"`

	EbikeId int64 `json:"ebike_id"`

	FaultId   int64  `json:"fault_id"`
	FaultName string `json:"fault_name"`

	FaultTypeId   int64  `json:"fault_type_id"`
	FaultTypeName string `json:"fault_type_name"`

	EbikeTypeId    int64  `json:"ebike_type_id"`
	EbikeTypeName  string `json:"ebike_type_name"`
	EbikeTypeImage string `json:"ebike_type_image"`

	Other string `json:"other"`

	Type int `json:"type"`

	Coordinate po.Point `json:"coordinate"`

	Photo pq.StringArray `json:"photo"`

	OrderNo string `json:"order_no"`

	Status int `json:"status"`

	Repairman int64 `json:"repairman"`

	Price int64 `json:"price"`

	StoreId int64 `json:"store_id"`

	StoreName string `json:"store_name"`

	Desc string `json:"desc"`

	RepairAt int64 `json:"repair_at"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

// RepairDeleteRequest 删除现场数据
type RepairDeleteRequest struct {
	Id int64 `json:"id"`
}

// RepairsEntityToDto entity数据转换
func RepairsEntityToDto(repairs []*entity.Repair) []*RepairInfo {
	out := make([]*RepairInfo, 0, len(repairs))
	for _, c := range repairs {
		out = append(out, RepairEntityToDto(c))
	}
	return out
}

// RepairEntityToDto entity数据转换
func RepairEntityToDto(e *entity.Repair) *RepairInfo {
	return &RepairInfo{

		Id: e.Id,

		Reportman: e.Reportman,

		EbikeId: e.EbikeId,

		FaultId: e.FaultId,

		FaultName: e.FaultName,

		FaultTypeId:    e.FaultTypeId,
		FaultTypeName:  e.FaultTypeName,
		EbikeTypeId:    e.EbikeTypeId,
		EbikeTypeName:  e.EbikeTypeName,
		EbikeTypeImage: e.EbikeTypeImage,

		Other: e.Other,

		Type: e.Type,

		Coordinate: e.Coordinate,

		Photo: e.Photo,

		OrderNo: e.OrderNo,

		Status: e.Status,

		Repairman: e.Repairman,

		Price: e.Price,

		StoreId: e.StoreId,

		Desc: e.Desc,

		RepairAt: e.RepairAt,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
